/**********************************************************************************
// SpaceRace Header File
// 
// Creation:	06 Mai 2011
// Updated:		23 Ago 2011
// Compiler:	Visual Studio 2011
//
// Notes:		Space Race is an asteroids inspired game in which
//              the player controls a space ship and must race the clock 
//              from one point to another destroing space waste and enemies 
//				along the way
//
**********************************************************************************/

#ifndef _SPACERACE_H_
#define _SPACERACE_H_

#define WIN32_LEAN_AND_MEAN  // just say no to MFC

#include "Resources.h"
#include "Anabele.h"
#include "Ship.h"
#include "Missile.h"
#include "GameTitle.h"
#include "Achievements.h"

#define NUMLEVELS 2

/**********************************************************************************/
/*                              SpaceRace Class                                   */
/**********************************************************************************/

class SpaceRace: public D3DGame
{
private:
	SceneManager scene;						// scene manager
	Input input;							// input system
	Sound sound;							// sound system
	
	Achievements * achievements;			// achievements 
	int achievementsPage;					// current achievement page been shown

	Font * smallFont;						// game font
	Font * titleFont;						// title font
	Font * bodyFont;						// title font

	Records records[NUMLEVELS];				// the best times in each level 
	float overallRecord;					// the best overall result of a single play
	float theoreticalBest;					// the best overall result of all plays
	float playerHistory[NUMLEVELS];			// player time for all levels
	float playerTime;						// player time for current level
	float playerOverall;					// sum of player times in all levels
	int recordColorIndex;					// number of color to use in record trace

	Background * backg;						// background image
	Sprite     * debugbox;					// debug box
	Sprite     * helpbar;					// help bar
	Sprite     * keymapbar;					// keymap bar
	Sprite	   * levelbar;					// level bar

	Ship * spaceShip;						// space ship sprite

	list<Missile *> missiles;				// list of active missiles
	list<Missile *>::iterator imis;			// iterator for active missiles list

	list<Sprite *> fixed;					// list of fixed game objects
	list<Sprite *>::iterator ifix;			// iterator for list of fixed game objects

	list<Sprite *> moving;					// list of moving game objects
	list<Sprite *>::iterator imov;			// iterator for list of moving game objects

	list<Sprite *> exploding;				// list of exploding game objects
	list<Sprite *>::iterator iexp;			// iterator for list of exploding game objects

	Sprite * missileExplosion;				// missile explosion sprite sheet
	Animation * missileExplosionAnim;		// missile explosion animation sequence

	list<Animation *> misExpList;			// list of missile explosion animations
	list<Animation *>::iterator iMisExp;	// iterator for list of missile explosion animations

	GameTitle * gameTitle;					// home screen

	int finPosX, finPosY;					// finish marker world coordinates
	
	Viewport playerVpBox;					// coordinates of a viewport centered on the player

	Rect borders[4];						// game world borders for collision
	Rect finishBB;							// finish marker
	Color finishColor;						// color to use on results	
	int finishColorIndex;					// selected finish color

	Trace playerTrace[1000];				// trace player path

	Sprite * traceDot[5];					// trace dots for ship trace
	uint dotsNum;							// number of dots

	Sprite * achievBar;						// achievements bar
	bool viewAchievements;					// wheather to show achievements list
	bool viewBoundingBoxes;					// wheather to draw the bounding boxes 
	bool viewPlayerTrace;					// wheather to show player trace
	bool inspectResult;						// wheather to fully inspect traces

	Sprite * stationOne;					// fixed station (level 1)
	Sprite * stationTwo;					// fixed station (level 2)
	Sprite * finish[3];						// finish sprite (green, yellow, red)

	Timer timer;							// game timer
	float timeLimit;						// level time limit
	float elapsedTime;						// level elapsed time
		
	char text[256];							// text buffer for printing strings

	int gameState;							// current game state
	int prevState;							// previous game state 
	int gameLevel;							// currente game level
		
public:
	SpaceRace();							// class constructor
	
	void GameInit();						// initialize game
	void GameLogic();						// game menu selection
	void GameUpdate();						// game common logic updates
	void GameDraw();						// drawing game objects
	void GameShutdown();					// ending game

	void Level1Init();						// level 1 initialization
	void Level1CleanUp();					// level 1 cleanup

	void Level2Init();						// level 2 initialization
	void Level2CleanUp();					// level 2 cleanup

	//void Level3Init();						// level 3 initialization
	//void Level3CleanUp();					// level 3 cleanup

	//void Level4Init();						// level 4 initialization
	//void Level4CleanUp();					// level 4 cleanup
};

/**********************************************************************************/

#endif
